home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Resources / Chat & Communication / Digsby build 37 / digsby_setup.exe / lib / util / primitives / refs.pyo (.txt) < prev    next >
Python Compiled Bytecode  |  2008-10-13  |  3KB  |  78 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.5)
  3.  
  4. from weakref import ref, ref as weakref_ref
  5. import new
  6.  
  7. def better_ref(method, cb = None, obj = None):
  8.     if obj is None:
  9.         return bound_ref(method, cb)
  10.     else:
  11.         return unbound_ref(obj, method, cb)
  12.  
  13.  
  14. class bound_ref(object):
  15.     
  16.     def __init__(self, method, cb = None):
  17.         funcinfo = funcinfo
  18.         import util.introspect
  19.         self.object = weakref_ref(method.im_self, cb)
  20.         self.func = weakref_ref(method.im_func)
  21.         self.cls = weakref_ref(method.im_class)
  22.  
  23.     
  24.     def __call__(self):
  25.         obj = self.object()
  26.         if obj is None:
  27.             return None
  28.         
  29.         func = self.func()
  30.         if func is None:
  31.             return None
  32.         
  33.         cls = self.cls()
  34.         if cls is None:
  35.             return None
  36.         
  37.         return new.instancemethod(func, obj, cls)
  38.  
  39.  
  40.  
  41. class unbound_ref(object):
  42.     
  43.     def __init__(self, obj, method, cb = None):
  44.         self.object = weakref_ref(obj)
  45.         self.func = weakref_ref(method)
  46.         if not hasattr(obj, '_unbound_cbs'):
  47.             obj._unbound_cbs = { }
  48.         
  49.         obj._unbound_cbs[self] = method
  50.  
  51.     
  52.     def __call__(self):
  53.         obj = self.object()
  54.         func = self.func()
  55.         if obj is not None and func is not None:
  56.             return func
  57.         
  58.  
  59.     
  60.     def __repr__(self):
  61.         funcinfo = funcinfo
  62.         import util
  63.         return '<unbound_ref to %s, obj is %r>' % (funcinfo(self.func()), self.object())
  64.  
  65.  
  66. better_ref_types = (bound_ref, unbound_ref)
  67.  
  68. class stupidref(ref):
  69.     
  70.     def __getattr__(self, attr):
  71.         return getattr(self(), attr)
  72.  
  73.  
  74. if __name__ == '__main__':
  75.     import doctest
  76.     doctest.testmod(verbose = True)
  77.  
  78.